package com.gljx.web.service.impl;

import com.gljx.web.Entity.Driving;
import com.gljx.web.dao.CommonDao;
import com.gljx.web.dao.DrivingMapper;
import com.gljx.web.dao.DrivingentrysMapper;
import com.gljx.web.service.DrivingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/11/3 0003.
 */
@Service
public class DrivingServiceImpl extends CommonDao implements DrivingService {

    @Autowired
    DrivingMapper drivingMapper;

    @Autowired
    DrivingentrysMapper drivingentrysMapper;

    /**
     * @Author lcx
     * @Date 2017/11/3 0003 下午 1:52
     * 查询协议驾校列表
     */
    @Override
    public List<Driving> selectDriving(String fcompanyid, String name) {
        return drivingMapper.selectDriving(fcompanyid, name);
    }

    /**
     * @Author lcx
     * @Date 2017/11/3 0003 下午 2:54
     * 根据id查询协议驾校
     */
    @Override
    public Driving queryDrivingByFid(String fid) {
        return drivingMapper.selectByPrimaryKey(fid);
    }

    /**
     * @Author lcx
     * @Date 2017/11/3 0003 下午 2:55
     * 修改
     */
    @Override
    public void modifyDrivingByFid(Driving driving) {
        drivingMapper.updateByPrimaryKeySelective(driving);
    }

    /**
     * @Author lcx
     * @Date 2017/11/6 0006 下午 3:59
     * 删除
     */
    @Override
    public void deleteByDrivingKey(String[] deleteId) {
        //删除记录
        for (int i = 0; i < deleteId.length; i++) {
            /*过滤为空的删除操作*/
            if (!deleteId[i].equals("")) {
                String did = deleteId[i];
                drivingMapper.deleteByPrimaryKey(did);
                drivingentrysMapper.deleteByFparentid(did);
            }
        }
    }

    /**
     * @Author lcx
     * @Date 2017/11/3 0003 下午 2:45
     * 添加协议驾校
     */
    @Override
    public void addDriving(Driving driving) {
        drivingMapper.insertSelective(driving);
    }

    /**
     * 查询全部协议驾校
     */
	@Override
    public List<Driving> queryDrivingAll(String companyId) {
        // TODO Auto-generated method stub
        return drivingMapper.selectDrivingAll(companyId);
    }

	/**
	 * 根据名称查询
	 */
	@Override
    public List<Driving> queryDrivingByFnameL2(String fnameL2, String companyId) {
        // TODO Auto-generated method stub
        Map<String, String> map = new HashMap<>();
        map.put("fnameL2", fnameL2);
        map.put("companyId", companyId);
        return drivingMapper.selectDrivingByFnameL2(map);
    }

	@Override
	public List<String> queryDrivingByInName(List<String> drivingName) {
		// TODO Auto-generated method stub
		return drivingMapper.selectDrivingByInName(drivingName);
	}


}
